#include <iostream>
#include <chrono>
#include <thread>
#include "windows.h"
#include <codecvt>

// 函数：显示进度条
void show_progress_bar(int progress, int total) {
    int barWidth = 70; // 进度条宽度
    float ratio = static_cast<float>(progress) / total;
    int pos = static_cast<int>(barWidth * ratio);

    std::cout << "[";
    for (int i = 0; i < barWidth; ++i) {
        if (i < pos) std::cout << ">";
        else if (i == pos) std::cout << ">";
        else std::cout << "-";
    }
    std::cout << "] " << int(ratio * 100.0) << " %\r";
    std::cout.flush();
}

int main() {
    SetConsoleOutputCP(CP_UTF8);
//    system("chcp 65001");
    const int total = 100; // 总进度
    // 设置区域为C++的本地环境
//    std::locale::global(std::locale(""));
    // 用于输出UTF-8字符串
//    std::wbuffer_convert<std::codecvt_utf8<wchar_t>> conv(std::cout.rdbuf());
//    std::wostream utf8out(&conv);
    std::cout.imbue(std::locale(""));
    std::cout << "任务开始！" << std::endl;
    for (int i = 0; i <= total; ++i) {
        show_progress_bar(i, total);
        std::this_thread::sleep_for(std::chrono::milliseconds(10)); // 模拟任务耗时
    }

    std::cout << std::endl;
    std::cout << "任务完成！" << std::endl;
    return 0;
}